import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPanel;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Date;
import java.util.Calendar;


public class DLoginInterface extends JFrame implements ActionListener
{
   // a JTextField for each number and one for the result
   private  JTextField number1JTextField = new JTextField(20);

   private final JTextField resultJTextField = new JTextField(20);
   public JLabel loginLabel = new JLabel("");
   public JButton computeJButton = new JButton("Login");
   public JButton back = new JButton("Back");
   public Container contents;
  
   // Construct a new window 
   public DLoginInterface()
   {  
      contents = getContentPane();
      setTitle("Driver login");
      contents.setLayout(new GridLayout(0, 1));

      // Add  textfields on the contents
      contents.add(new JLabel("driver ID: "));
      contents.add(number1JTextField);
     
      // create a new button and add it to the contents
      contents.add(computeJButton);
      // add a ActionListener for this button
      computeJButton.addActionListener(this);
      
      contents.add(back);
      back.addActionListener(this);
      // add in the contents a textlabel 
      contents.add(loginLabel);
      // display the result in the restultextfield
      //  contents.add(resultJTextField);
      // exit the program in case the window it's closed
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      pack();
   } //cont
   
   private driverInterface first;
   private iniInterface ini;
   public void actionPerformed(ActionEvent event)
   {  //for id login
      if (event.getSource() == computeJButton)
      {
        if(Controller.checkDriverID(number1JTextField.getText()))
        { dispose();
          first = new driverInterface(DriverInfo.findDriver(number1JTextField.getText()));
          first.setVisible(true);
        }
	else loginLabel.setText("Invalid ID");
      }
      else if (event.getSource() == back)
      {
          dispose();
          ini = new iniInterface();
          ini.setVisible(true);
      }
      
   } // actionPerformed
} // class
